package cn.domob.android.ads;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.net.Uri;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.Toast;
import android.widget.VideoView;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

class x
{
  private static final String A = "domob_banner.png";
  private static final String B = "domob_exit.png";
  private static final String C = "domob_exit_on.png";
  private static final String D = "domob_loading.png";
  private static final String E = "domob_next_off.png";
  private static final String F = "domob_next.png";
  private static final String G = "domob_next_on.png";
  private static final String H = "domob_out.png";
  private static final String I = "domob_out_on.png";
  private static final String J = "domob_preview_off.png";
  private static final String K = "domob_preview.png";
  private static final String L = "domob_preview_on.png";
  private static final String M = "domob_refresh.png";
  private static final String N = "domob_refresh_on.png";
  private static final int O = 35;
  private static final int P = 35;
  private static final int Q = 45;
  private static final int R = 500;
  private static final String[] S;
  private static J a = new J(x.class.getSimpleName());
  private static final String w = "domob";
  private static final String x = "close";
  private static final String y = "inapp";
  private static final String z = "url";
  private WebView b;
  private String c = null;
  private Context d = null;
  private String e;
  private Dialog f = null;
  private b g;
  private Handler h = new Handler();
  private RelativeLayout i;
  private float j = 1.0F;
  private View k;
  private ImageButton l;
  private ImageButton m;
  private ImageButton n;
  private ImageButton o;
  private ImageButton p;
  private ImageView q;
  private RotateAnimation r;
  private Animation s;
  private Animation t;
  private boolean u = false;
  private boolean v = false;

  static
  {
    S = new String[] { ".mp4", ".3gp", ".asf", ".avi", ".m4u", ".m4v", ".mov", ".mp4", ".mpe", ".mpeg", ".mpg", ".mpg4" };
  }

  public x(Context paramContext, String paramString1, String paramString2, b paramb)
  {
    a.a(this, "Initialize DomobLandingPageBuilder");
    this.d = paramContext;
    this.j = q.u(this.d);
    this.b = new WebView(this.d);
    this.c = paramString1;
    this.e = paramString2;
    this.g = paramb;
    try
    {
      this.k = d();
      e();
      return;
    }
    catch (Exception localException)
    {
      a.a(localException);
    }
  }

  private Drawable a(Context paramContext, String paramString)
  {
    try
    {
      BitmapDrawable localBitmapDrawable = new BitmapDrawable(BitmapFactory.decodeStream(super.getClass().getClassLoader().getResourceAsStream("assets/" + paramString)));
      return localBitmapDrawable;
    }
    catch (Exception localException)
    {
      a.a(localException);
      a.e("Failed to load source file:" + paramString);
    }
    return null;
  }

  private LinearLayout a(String paramString, ImageButton paramImageButton)
  {
    LinearLayout localLinearLayout = new LinearLayout(this.d);
    paramImageButton.setBackgroundDrawable(a(this.d, paramString));
    paramImageButton.setLayoutParams(new LinearLayout.LayoutParams((int)(35.0F * this.j), (int)(35.0F * this.j)));
    localLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(-2, -2, 1.0F));
    localLinearLayout.setGravity(17);
    localLinearLayout.addView(paramImageButton);
    return localLinearLayout;
  }

  private boolean a(int paramInt1, int paramInt2)
  {
    int i1 = -1 + Integer.toBinaryString(paramInt2).length();
    return (paramInt1 >>> i1) % 2 == (paramInt2 >>> i1) % 2;
  }

  private View d()
    throws IOException
  {
    LinearLayout localLinearLayout = new LinearLayout(this.d);
    localLinearLayout.setOrientation(0);
    localLinearLayout.setGravity(17);
    localLinearLayout.setBackgroundDrawable(a(this.d, "domob_banner.png"));
    localLinearLayout.addView(j());
    localLinearLayout.addView(l());
    localLinearLayout.addView(p());
    localLinearLayout.addView(n());
    localLinearLayout.addView(h());
    return localLinearLayout;
  }

  private void e()
    throws IOException
  {
    this.q = new ImageView(this.d);
    this.q.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeStream(super.getClass().getClassLoader().getResourceAsStream("assets/domob_loading.png"))));
    this.q.setVisibility(8);
    this.r = new RotateAnimation(0.0F, 360.0F, 1, 0.5F, 1, 0.5F);
    this.r.setDuration(1000L);
    this.r.setInterpolator(new LinearInterpolator());
    this.r.setRepeatCount(-1);
  }

  private boolean f()
  {
    if (this.d instanceof Activity)
      return a(((Activity)this.d).getWindow().getAttributes().flags, 1024);
    return false;
  }

  private WebView g()
  {
    s();
    this.b.setVisibility(0);
    this.b.getSettings().setJavaScriptEnabled(true);
    this.b.getSettings().setPluginsEnabled(true);
    this.b.setDownloadListener(new DownloadListener()
    {
      public void onDownloadStart(String paramString1, String paramString2, String paramString3, String paramString4, long paramLong)
      {
        String str = paramString1.substring(paramString1.lastIndexOf("."));
        x.b().a(x.this, paramString1 + "----on Download start:" + str);
        if (Arrays.asList(x.c()).contains(str))
        {
          boolean bool = x.e(x.this) instanceof Activity;
          Activity localActivity = null;
          if (bool)
            localActivity = (Activity)x.e(x.this);
          if ((localActivity == null) || (!localActivity.isFinishing()))
          {
            x.a(x.this, true);
            x.f(x.this);
            Toast.makeText(x.e(x.this), "Loading video...", 0).show();
            Dialog localDialog = new Dialog(x.e(x.this), 16973831);
            localDialog.setOnDismissListener(new DialogInterface.OnDismissListener()
            {
              public void onDismiss(DialogInterface paramDialogInterface)
              {
                x.b().b(x.this, "Video dialog dismissed.");
                x.a(x.this, false);
                x.g(x.this);
                if (x.h(x.this) != null)
                  return;
                x.i(x.this);
              }
            });
            VideoView localVideoView = new VideoView(x.e(x.this));
            localVideoView.setVideoURI(Uri.parse(paramString1));
            MediaController localMediaController = new MediaController(x.e(x.this));
            localMediaController.setMediaPlayer(localVideoView);
            localMediaController.setAnchorView(localVideoView);
            localVideoView.setMediaController(localMediaController);
            localVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener()
            {
              public boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2)
              {
                x.b().e(x.this, "Video play error.");
                return false;
              }
            });
            localVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(localDialog)
            {
              public void onCompletion(MediaPlayer paramMediaPlayer)
              {
                this.a.dismiss();
              }
            });
            RelativeLayout localRelativeLayout = new RelativeLayout(x.e(x.this));
            localRelativeLayout.setBackgroundColor(-16777216);
            localRelativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
            RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -1);
            localLayoutParams.addRule(13);
            localRelativeLayout.addView(localVideoView, localLayoutParams);
            localDialog.setContentView(localRelativeLayout);
            localDialog.show();
            localVideoView.start();
            localVideoView.requestFocus();
          }
        }
        do
        {
          return;
          x.b().b("should not alert a dialog now");
          return;
        }
        while (x.c(x.this) == null);
        x.c(x.this).a(paramString1, x.h(x.this));
      }
    });
    this.b.setWebViewClient(new a());
    this.b.setWebChromeClient(new WebChromeClient()
    {
      public void onProgressChanged(WebView paramWebView, int paramInt)
      {
        x.j(x.this);
        super.onProgressChanged(paramWebView, paramInt);
      }
    });
    RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -1);
    localLayoutParams.addRule(12);
    this.b.setLayoutParams(localLayoutParams);
    this.b.loadUrl(this.c);
    return this.b;
  }

  private LinearLayout h()
  {
    this.p = new ImageButton(this.d);
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams((int)(35.0F * this.j), (int)(35.0F * this.j));
    this.p.setLayoutParams(localLayoutParams);
    this.p.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        x.i(x.this);
      }
    });
    this.p.setOnTouchListener(new View.OnTouchListener()
    {
      public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
      {
        if (paramMotionEvent.getAction() == 0)
          x.k(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_exit_on.png"));
        while (true)
        {
          return false;
          if (paramMotionEvent.getAction() != 1)
            continue;
          x.k(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_exit.png"));
        }
      }
    });
    return a("domob_exit.png", this.p);
  }

  private void i()
  {
    this.t = new TranslateAnimation(1, 0.0F, 1, 0.0F, 1, 0.0F, 1, 1.0F);
    this.t.setDuration(500L);
    this.i.startAnimation(this.t);
    this.h.postDelayed(new Runnable()
    {
      public void run()
      {
        x.l(x.this).dismiss();
      }
    }
    , 500L);
  }

  private LinearLayout j()
  {
    this.l = new ImageButton(this.d);
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams((int)(35.0F * this.j), (int)(35.0F * this.j));
    this.l.setLayoutParams(localLayoutParams);
    if (this.b.canGoBack());
    for (String str = "domob_preview.png"; ; str = "domob_preview_off.png")
    {
      this.l.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramView)
        {
          x.m(x.this);
        }
      });
      this.l.setOnTouchListener(new View.OnTouchListener()
      {
        public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
        {
          if (x.a(x.this).canGoBack())
          {
            if (paramMotionEvent.getAction() != 0)
              break label48;
            x.n(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_preview_on.png"));
          }
          while (true)
          {
            return false;
            label48: if (paramMotionEvent.getAction() != 1)
              continue;
            x.n(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_preview.png"));
          }
        }
      });
      return a(str, this.l);
    }
  }

  private void k()
  {
    if (this.b == null);
    do
      return;
    while (!this.b.canGoBack());
    this.b.goBack();
    r();
  }

  private LinearLayout l()
  {
    this.m = new ImageButton(this.d);
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams((int)(35.0F * this.j), (int)(35.0F * this.j));
    this.m.setLayoutParams(localLayoutParams);
    this.m.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        x.o(x.this);
      }
    });
    this.m.setOnTouchListener(new View.OnTouchListener()
    {
      public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
      {
        if (x.a(x.this).canGoForward())
        {
          if (paramMotionEvent.getAction() != 0)
            break label48;
          x.p(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_next_on.png"));
        }
        while (true)
        {
          return false;
          label48: if (paramMotionEvent.getAction() != 1)
            continue;
          x.p(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_next.png"));
        }
      }
    });
    return a("domob_next_off.png", this.m);
  }

  private void m()
  {
    if (this.b == null);
    do
      return;
    while (!this.b.canGoForward());
    this.b.goForward();
    r();
  }

  private LinearLayout n()
  {
    this.n = new ImageButton(this.d);
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams((int)(35.0F * this.j), (int)(35.0F * this.j));
    this.n.setLayoutParams(localLayoutParams);
    this.n.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        try
        {
          x.q(x.this);
          return;
        }
        catch (Exception localException)
        {
          x.b().e(this, "intent " + x.r(x.this) + " error");
        }
      }
    });
    this.n.setOnTouchListener(new View.OnTouchListener()
    {
      public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
      {
        if (paramMotionEvent.getAction() == 0)
          x.s(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_out_on.png"));
        while (true)
        {
          return false;
          if (paramMotionEvent.getAction() != 1)
            continue;
          x.s(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_out.png"));
        }
      }
    });
    return a("domob_out.png", this.n);
  }

  private void o()
  {
    Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(this.c));
    this.d.startActivity(localIntent);
  }

  private LinearLayout p()
  {
    this.o = new ImageButton(this.d);
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams((int)(35.0F * this.j), (int)(35.0F * this.j));
    this.o.setLayoutParams(localLayoutParams);
    this.o.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        try
        {
          x.t(x.this);
          return;
        }
        catch (Exception localException)
        {
          x.b().e(this, "intent " + x.r(x.this) + " error");
        }
      }
    });
    this.o.setOnTouchListener(new View.OnTouchListener()
    {
      public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
      {
        if (paramMotionEvent.getAction() == 0)
          x.u(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_refresh_on.png"));
        while (true)
        {
          return false;
          if (paramMotionEvent.getAction() != 1)
            continue;
          x.u(x.this).setBackgroundDrawable(x.a(x.this, x.e(x.this), "domob_refresh.png"));
        }
      }
    });
    return a("domob_refresh.png", this.o);
  }

  private void q()
  {
    if (this.b == null)
      return;
    this.b.reload();
  }

  private void r()
  {
    if (this.b.canGoBack())
      this.l.setBackgroundDrawable(a(this.d, "domob_preview.png"));
    while (this.b.canGoForward())
    {
      this.m.setBackgroundDrawable(a(this.d, "domob_next.png"));
      return;
      this.l.setBackgroundDrawable(a(this.d, "domob_preview_off.png"));
    }
    this.m.setBackgroundDrawable(a(this.d, "domob_next_off.png"));
  }

  private void s()
  {
    int i1 = 1;
    int i2;
    if (this.q != null)
    {
      i2 = i1;
      label11: if (this.q == null)
        break label49;
    }
    while (true)
    {
      if ((i2 & i1) != 0)
      {
        this.q.setVisibility(0);
        this.q.startAnimation(this.r);
      }
      return;
      i2 = 0;
      break label11:
      label49: i1 = 0;
    }
  }

  private void t()
  {
    int i1 = 1;
    int i2;
    label11: int i3;
    label20: int i4;
    if (this.q != null)
    {
      i2 = i1;
      if (this.q == null)
        break label61;
      i3 = i1;
      i4 = i2 & i3;
      if (this.v)
        break label66;
    }
    while (true)
    {
      if ((i4 & i1) != 0)
      {
        this.q.clearAnimation();
        this.q.setVisibility(8);
      }
      return;
      i2 = 0;
      break label11:
      label61: i3 = 0;
      break label20:
      label66: i1 = 0;
    }
  }

  protected Dialog a()
    throws Exception
  {
    a.a(this, "Start to build FS/RFS landingpage");
    this.i = new RelativeLayout(this.d);
    this.i.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
    this.i.addView(g());
    RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-2, -2);
    localLayoutParams1.addRule(13);
    this.i.addView(this.q, localLayoutParams1);
    if (f())
    {
      this.f = new Dialog(this.d, 16973841);
      RelativeLayout.LayoutParams localLayoutParams3 = new RelativeLayout.LayoutParams(-2, -2);
      localLayoutParams3.addRule(11);
      this.i.addView(h(), localLayoutParams3);
    }
    while (true)
    {
      this.s = new TranslateAnimation(1, 0.0F, 1, 0.0F, 1, 1.0F, 1, 0.0F);
      this.s.setDuration(500L);
      this.i.startAnimation(this.s);
      this.f.getWindow().getAttributes().dimAmount = 0.5F;
      this.f.getWindow().setFlags(2, 2);
      this.f.setContentView(this.i);
      this.f.setOnDismissListener(new DialogInterface.OnDismissListener()
      {
        public void onDismiss(DialogInterface paramDialogInterface)
        {
          x.b(x.this).removeView(x.a(x.this));
          if (x.c(x.this) != null)
            x.c(x.this).E();
          if ((x.d(x.this)) || (x.c(x.this) == null))
            return;
          x.c(x.this).D();
        }
      });
      return this.f;
      this.f = new Dialog(this.d, 16973840);
      ((RelativeLayout.LayoutParams)this.b.getLayoutParams()).bottomMargin = (int)(45.0F * this.j);
      RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-1, (int)(45.0F * this.j));
      localLayoutParams2.addRule(12);
      this.i.addView(this.k, localLayoutParams2);
    }
  }

  class a extends WebViewClient
  {
    a()
    {
    }

    public void onPageFinished(WebView paramWebView, String paramString)
    {
      super.onPageFinished(paramWebView, paramString);
      x.b().a("onPageFinished with URL:" + paramString);
      x.b(x.this, true);
      if (x.c(x.this) != null)
        x.c(x.this).B();
      x.g(x.this);
      x.j(x.this);
    }

    public void onPageStarted(WebView paramWebView, String paramString, Bitmap paramBitmap)
    {
      super.onPageStarted(paramWebView, paramString, paramBitmap);
      x.b().a("onPageStarted with URL:" + paramString);
      x.f(x.this);
      x.j(x.this);
    }

    public void onReceivedError(WebView paramWebView, int paramInt, String paramString1, String paramString2)
    {
      super.onReceivedError(paramWebView, paramInt, paramString1, paramString2);
      if (x.c(x.this) != null)
        x.c(x.this).C();
      J localJ = x.b();
      x localx = x.this;
      Object[] arrayOfObject = new Object[3];
      arrayOfObject[0] = Integer.valueOf(paramInt);
      arrayOfObject[1] = paramString1;
      arrayOfObject[2] = paramString2;
      localJ.e(localx, String.format("WebView ReceivedError, errorCode=%d, description=%s, failingUrl=%s", arrayOfObject));
    }

    public boolean shouldOverrideUrlLoading(WebView paramWebView, String paramString)
    {
      x.b().a("Override URL loading in landing page:" + paramString);
      Uri localUri;
      if (paramString.startsWith("domob"))
      {
        localUri = Uri.parse(paramString);
        String str1 = localUri.getHost();
        if (str1.equals("close"))
        {
          x.i(x.this);
          return true;
        }
        if (!str1.equals("inapp"));
      }
      String str2;
      try
      {
        String str3 = localUri.getQueryParameter("url");
        str2 = str3;
        label86: x.b().a("Load landing page with URL:" + str2);
        paramWebView.loadUrl(str2);
        if (x.c(x.this) != null);
        x.c(x.this).g(paramString);
        return true;
      }
      catch (Exception localException)
      {
        x.b().e("Error happened during loading Landing Page.");
        x.b().a(localException);
        str2 = null;
        break label86:
        if (paramString.startsWith("http"));
        paramWebView.loadUrl(paramString);
      }
    }
  }

  public static abstract interface b
  {
    public abstract void B();

    public abstract void C();

    public abstract void D();

    public abstract void E();

    public abstract void a(String paramString1, String paramString2);

    public abstract void g(String paramString);
  }
}

/* Location:           C:\Users\god\Desktop\liunianjishiben_V1.1_mumayi_3745b_dex2jar.jar
 * Qualified Name:     cn.domob.android.ads.x
 * JD-Core Version:    0.5.4
 */